<link href="Style.css" rel="stylesheet" type="text/css" />
<?php
session_start(); 

require("sql_functions.php");

if(isset($_SESSION['user']))
{
	$user = $_SESSION['user'];

	$projects = sql_getUserProjects($user);
	echo "<form action=\"\" method=\"GET\">"; 
	echo "<p>Select a project:";
	echo "<select name=\"projectID\">";
	while($row = mysql_fetch_array($projects))
	{
		$name = $row['Title'];
		$pid = $row['ID'];
		$mgrEmail = $row['ManagerEmail'];
		if(!strcmp($mgrEmail, $user))
		{
			echo "<option value=\"$pid\"> $name </option>";
		}

	}
	echo "</select>";

	echo "<p><input type=\"submit\" value=\"Submit\" />"; 
	echo "</form>";   

	if($_GET['projectID'])
	{
		$pid = $_GET['projectID'];
		$project = sql_getProject($pid);
		$milestones = sql_getProjectMilestones($pid);

		$pName = $project['Title'];

		echo "<html>"; 
		echo "<head>"; 
		echo "</head>"; 
		echo "<body>";
		echo "<p>Project Tasks Report for $pName"; 
		
		echo "<table border='1'>";	
		echo "<tr><td>Task Name</td><td>Due Date</td><td>Assigned To</td><td>Status</td><td>Total Hours</td>";
		while($row = mysql_fetch_array($milestones))
		{		
			$mName = $row['Name'];
			$mDueDate = makePHPDate($row['DueDate']);      
			$mStatus = $row['IsComplete'];
      
      if($mStatus)
      {
        $mStatus = "Closed";
      }
      else
      {
        $mStatus = "Active";
      }
      
			$mTotalHours = sql_getMilestoneHours($pid, $mName);

			echo "<tr><td>";
			echo "<b>$mName</b>";
			echo "</td><td>";
			echo "<b>$mDueDate</b>";
			echo "</td><td>";
			echo "";
			echo "</td><td>";
			echo "<b>$mStatus</b>";
			echo "</td><td>";
			echo "<b>$mTotalHours</b>";
			echo "</td></tr>";
			
			$tasks = sql_getMilestoneTasks($pid, $mName);
			while($row = mysql_fetch_array($tasks))
			{
				$tName = $row['TaskName'];
				$tDueDate = makePHPDate($row['DueDate']);
        $tAssignedTo = $row['EmployeeEmail'];
				$tStatus = $row['IsClosed'];
        
        if($tStatus)
        {
          $tStatus = "Closed";
        }
        else
        {
          $tStatus = "Open";
        }
        
        
				$tTotalHours = sql_getTaskHours($pid, $mName, $tName);

				echo "<tr><td>";
				echo "$tName";
				echo "</td><td>";
				echo "$tDueDate";
				echo "</td><td>";
				echo "$tAssignedTo";
				echo "</td><td>";
				echo "$tStatus";
				echo "</td><td>";
				echo "$tTotalHours";
				echo "</td></tr>";
			}

		}
		echo "</table>";
    	
		echo "</body>"; 
		echo "</html>";  
	}

}
else
{
	echo "Must be logged in to view this page.";
}

?>




